package com.atguigu.tingshu.account.api;

import com.atguigu.tingshu.account.service.RechargeInfoService;
import com.atguigu.tingshu.common.anno.GuiGuLogin;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.model.account.RechargeInfo;
import com.atguigu.tingshu.vo.account.RechargeInfoVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.handler.annotation.Header;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@Tag(name = "充值管理")
@RestController
@RequestMapping("api/account/rechargeInfo")
@SuppressWarnings({"unchecked", "rawtypes"})
public class RechargeInfoApiController {

	@Autowired
	private RechargeInfoService rechargeInfoService;

	/**
	 * @description: 账户充值功能 保存充值订单 订单状态为未支付
	 * @author Petrichor
	 * @date 2024/1/11 10:11
	 * @param rechargeInfoVo 充值对象 [充值金额  	支付方式：1101-微信 1102-支付宝]
	 * @return 订单号
	**/
	@GuiGuLogin
	@Operation(summary = "充值")
	@PostMapping("submitRecharge")
	public Result<Map<String , String>> submitRecharge(@RequestBody RechargeInfoVo rechargeInfoVo){
		String orderNo = this.rechargeInfoService.submitRecharge(rechargeInfoVo);
		HashMap<String, String> map = new HashMap<>();
		map.put("orderNo",orderNo);
		return Result.ok(map);
	}
	/**
	 * @description: 根据订单号获取充值信息
	 * @author Petrichor
	 * @date 2024/1/11 10:34
	 * @param orderNo 订单号
	 * @return 充值订单信息
	**/
	@GuiGuLogin
	@Operation(summary = "根据订单号获取充值信息")
	@GetMapping("/getRechargeInfo/{orderNo}")
	public Result<RechargeInfo> getRechargeInfo(@PathVariable("orderNo") String orderNo){
		RechargeInfo rechargeInfo = rechargeInfoService.getRechargeInfoByOrderNo(orderNo);
		return Result.ok(rechargeInfo);
	}
}

